{% extends "saltstack/index.html" %}

{% block right_content %}
<div id="right_menu">
    <table id="example" style="table-layout:fixed;text-align: center;" class="table table-bordered table-hover">
        <thead >
            <td>主机</td>
            <td>状态</td>
            <td>操作</td>
        </thead>
        {% if salt_key_list %}
        {% for node in salt_key_list %}
        <tr>
            <td>{{ node.minions }}</td>
            <td>{{ node.key_status_desc }}</td>
            <td>
                <div>
                    {% ifequal node.key_status 0 %}
                    <a class="accept_key btn btn-info" data-hostname="{{ node.minions }}"
                                 data-toggle="modal" data-target="#acceptKey"><span class="glyphicon glyphicon-ok"></span></a>
                    {% else %}
                    <!-- <button  type="button" class="delete_key btn btn-info" data-hostname="{{ node.minions }}"
                                 data-toggle="modal" data-target="#deleteKey">删除</button> -->
                                  <a class="delete_key mouse_pointer hint hint-top" data-hint="删除此记录!"><span class="glyphicon glyphicon-trash"></span></a>
                    {% endifequal %}

                </div>
            </td>
        </tr>
        {% endfor %}
        {% endif %}
    </table>

    <div>
        <span>跳转到
         <select class="pagei">
             {% for temppage in page_list %}
             <option value="{{ temppage }}" {% ifequal temppage page %}selected {% endifequal %}>{{ temppage }}</option>
             {% endfor %}
         </select>页
        </span>
        <span style="padding-left: 28%;">每页{{ page_num }}条，第{{ page }}页，共{{ count }}条，共{{ page_total }}页</span>
        <span style="float:right;padding-right:50px">
            <a class="word" href="{% url 'saltstack:keyList' %}?page=1">首页</a>
            {% ifnotequal page 1 %}
            <a href="{% url 'saltstack:keyList' %}?page={{ page|add:-1 }}">上一页</a>
            {% endifnotequal %}
            {% ifnotequal page page_total %}
            <a href="{% url  'saltstack:keyList' %}?page={{ page|add:1 }}">下一页</a>
            {% endifnotequal %}
            <a class="word" href="{% url 'saltstack:keyList' %}?page={{ page_total }}">尾页</a>
        </span>
    </div>

</div>

<script type="text/javascript">
    $(".pagei").change(function(){
        var index=$(this).children('option:selected').val();
        window.location.href="{% url 'saltstack:keyList' %}?page=" + index;
    });

    $(".accept_key").click(function(){
        var hostname = $(this).data("hostname");
        var urls = "{% url 'saltstack:keyAccept' %}";
        var postdata = {node_name:hostname};
        var jsonstr = $.ajax({
            url : urls,
		    type : "POST",
		    data : postdata,
		    async : false,
		    cache : false
	    });
	    var jsonobj = eval('(' + jsonstr.responseText + ')');
	    if(jsonobj.status == 1){
	        window.location.reload();
	    }else{
	         alert(jsonobj.message);
	    }
    });

    $(".delete_key").click(function(){
    if(confirm("确定要删除吗？删除操作不可恢复！")) {
        var hostname = $(this).data("hostname");
        var urls = "{% url 'saltstack:keyDelete' %}";
        var postdata = {node_name:hostname};
        var jsonstr = $.ajax({
            url : urls,
		    type : "POST",
		    data : postdata,
		    async : false,
		    cache : false
	    });
	    var jsonobj = eval('(' + jsonstr.responseText + ')');
	    if(jsonobj.status == 1){
	        window.location.reload();
	    }else{
	         alert(jsonobj.message);
	    }
	    }
    });

</script>
{% endblock %}